package abstract1.temp;

/**
 * Created with IntelliJ IDEA.
 * ClassName: TemplateTest
 * Package: abstract1.temp
 * Description:
 * User: fzykd
 *
 * @Author: LQH
 * Date: 2023-11-24
 * Time: 20:24
 */

public class TemplateTest {

    public static void main(String[] args) {
        PrintNumber p = new PrintNumber();
        p.spendTime();
    }

}


abstract class Template {

    //计算某段代码的执行需要花费的时间
    public void spendTime() {

        long start = System.currentTimeMillis();
        //执行的某一段代码 不确定 不确定就放到另一个方法当中
        code();
        long end = System.currentTimeMillis();

        System.out.println("花费的时间为: " + (end - start));


    }

    //具体是什么代码 就交给子类去实现了
    public abstract void code();


}

class PrintNumber extends Template {

    @Override
    public void code() {

        for (int i = 2; i <= 100000; i++) {
            boolean isFlag = true;

            for (int j = 2; j <= Math.sqrt(i); j++) {
                if (i % j == 0) {
                    isFlag = false;
                    break;
                }
            }
            if (isFlag) {
                System.out.println(i);
            }
        }

    }
}